package com.woniuxy.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.core.service.AllArticleService;
import com.woniuxy.core.service.RelArticleTypeService;
import com.woniuxy.core.mapper.RelArticleTypeMapper;
import com.woniuxy.entity.DTO.ArticleUserDTO;
import com.woniuxy.entity.RelArticleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author nanqiao
* @description 针对表【rel_article_type】的数据库操作Service实现
* @createDate 2025-07-12 14:22:57
*/
@Service
public class RelArticleTypeServiceImpl extends ServiceImpl<RelArticleTypeMapper, RelArticleType>
    implements RelArticleTypeService{
    @Autowired
    private AllArticleService allArticleService;

    @Override
    public List<ArticleUserDTO> getArticlesByTypeId(Integer typeId) {
        return allArticleService.selectArticlesByTypeId(typeId);
    }
    // RelArticleTypeServiceImpl.java

    @Override
    public void addRelations(Long articleId, List<Integer> typeIds) {
        List<RelArticleType> relations = typeIds.stream()
                .map(typeId -> {
                    RelArticleType relation = new RelArticleType();
                    relation.setArticleId(articleId);
                    relation.setTypeId(typeId);
                    return relation;
                })
                .collect(Collectors.toList());

        this.saveBatch(relations);
    }

}




